<?php

namespace App\Admin\Controllers\Customer;

use App\model\customer\CustomerHangye;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class CustomerHangyeController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '行业';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new CustomerHangye());

        //$grid->column('hangye_id', __('Hangye id'));
        $grid->column('name', __('名称'));
        $grid->column('alias', __('别名'));
        $states = [
            'on' => ['value' => 1, 'text' => '是', 'color' => 'success'],
            'off' => ['value' => 0, 'text' => '否', 'color' => 'danger'],
        ];
        $grid->column('is_display', __('是否展示'))->switch($states);
        $grid->column('sort', __('排序'));
        $grid->column('created_at', __('创建时间'));
        //$grid->column('updated_at', __('Updated at'));

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(CustomerHangye::findOrFail($id));

        $show->field('hangye_id', __('Hangye id'));
        $show->field('name', __('Name'));
        $show->field('is_display', __('Is display'));
        $show->field('sort', __('Sort'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));
        $show->field('alias', __('Alias'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new CustomerHangye());

        $form->text('name', __('名称'));
        $form->text('alias', __('别名'));
        $states = [
            'on' => ['value' => 1, 'text' => '是', 'color' => 'success'],
            'off' => ['value' => 0, 'text' => '否', 'color' => 'danger'],
        ];
        $form->switch('is_display', __('是否展示'))->states($states)->default(1);
        $form->number('sort', __('排序'));

        return $form;
    }
}
